package com.baizhi.service.impl;


import com.baizhi.dao.AlbumMapper;
import com.baizhi.entity.Album;
import com.baizhi.service.AlbumService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/27 11:46
 * @Description:
 */
@Service
@Transactional
public class AlbumServiceImpl implements AlbumService {
    @Autowired
    private AlbumMapper albumMapper;
    @Override
    public Map selectByPage(int rows, int page) {
        Map map=new HashMap();
        IPage<Album> iPage=new Page(rows,page);
        IPage<Album> albumIPage =albumMapper.selectPage(iPage,null);
        List<Album> list=albumIPage.getRecords();

        long count=albumIPage.getTotal();

        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public void insert(Album album) {
        albumMapper.insert(album);
    }

    @Override
    public void update(Album album) {
        albumMapper.updateById(album);

    }

    @Override
    public void deleteMore(int[] ids) {
        for (int id:ids) {
           albumMapper.deleteById(id);
        }
    }
}
